package com.itheima.controller;

import com.itheima.domain.Account;
import com.itheima.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService as;

    @RequestMapping("/findAll")
    public String findAll(Model model){
        System.out.println("表现层查询所有的账户信息");
        //调用业务层
        List<Account> accounts = as.findAll();
        model.addAttribute("accounts",accounts);
        return "list";
    }

    @RequestMapping("/save")
    public String save(Account account){
        System.out.println("save........");
        as.saveAccount(account);
        return "redirect:http://localhost:8080/ssm/account/findAll";
    }
}
